<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.2.1.min.js"></script>
    <script>
        var nameArray,telArray,emailArray,birArray;
        $(function () {
             nameArray=[$("#name")[0],$("#name").next()[0],
                /^[a-zA-Z\u4e00-\u9fa5]{2,}$/,"姓名必须为两位以上的字母或汉字"];
             telArray=[$("#tel")[0],$("#tel").next()[0],
                /^1[3578]\d{9}$/,
                "电话必须为13、15、17、18开始的11位数"];
             emailArray=[$("#email")[0],$("#email").next()[0],
                /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/,
                "请输入正确的邮箱表达式"];
             birArray=[$("#birthday")[0],$("#birthday").next()[0],
                /^(19|bai20)\d{2}-(1[0-2]|0?[1-9])-(0?[1-9]|[1-2][0-9]|3[0-1])$/,
                "请输入正确的生日格式，格式为XXXX-XX-XX"];
            $("#name").blur(function () {
                check(nameArray);
            });
            $("#tel").blur(function () {
                check(telArray);
            });
            $("#email").blur(function () {
                check(emailArray);
            });
            $("#birthday").blur(function () {
                check(birArray);
            });
        });


        function check(array) {
            if(array[2].test(array[0].value)){
                array[1].innerHTML = "验证通过";
                array[1].style.color = "green";
                return true;
            }
            else{
                array[1].style.color = "red";
                array[1].innerHTML=array[3];
                return false;
            }
        }



        function checkForm() {
            return check(nameArray) &&  check(telArray) && check(emailArray) && check(birArray);
        }
    </script>
</head>
<body>
<form action="add" method="get" onsubmit="return checkForm();">
    姓名：<input type="text" id="name" name="name"
             ><span ></span><br>
    电话：<input type="text" id="tel" name="tel"><span ></span><br>
    e-mail：<input type="text" id="email" name="email"><span></span><br>
    生日：<input type="text" id="birthday" name="birthday"><span ></span><br>
    <input type="submit" value="提交">
</form>


</body>
</html>